package cn.com.git.workflow.service.impl;

import cn.com.git.common.base.BaseServiceImpl;
import cn.com.git.common.exception.ApiException;
import cn.com.git.common.model.CommonStateConstant;
import cn.com.git.common.model.ResultConstant;
import cn.com.git.common.model.ResultMsg;
import cn.com.git.common.model.ResultPage;
import cn.com.git.common.util.object.JSONUtils;
import cn.com.git.common.util.object.MapperFacadeUtils;
import cn.com.git.workflow.common.WorkFlowNodeOperateEnum;
import cn.com.git.workflow.common.WorkFlowNodeEnum;
import cn.com.git.workflow.dao.*;
import cn.com.git.workflow.dao.model.WorkFlow;
import cn.com.git.workflow.dao.model.WorkFlowConfig;
import cn.com.git.workflow.dao.model.WorkFlowOperate;
import cn.com.git.workflow.service.WorkFlowService;
import cn.com.git.workflow.service.dto.*;
import cn.com.git.workflow.service.query.WorkFlowConfigListQuery;
import cn.com.git.workflow.service.query.WorkFlowListQuery;
import cn.com.git.workflow.service.query.WorkFlowOperateListQuery;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

/**
* WorkFlow ServiceImpl 接口
* @author zhangzhenfu
* @Description
* @date 2020/4/13
*/
@Transactional
@Service
public class WorkFlowServiceImpl extends BaseServiceImpl implements WorkFlowService {

    @Autowired
    private WorkFlowDAO workFlowDAO;
    @Autowired
    private WorkFlowOperateDAO workFlowOperateDAO;
    @Autowired
    private WorkFlowConfigDAO workFlowConfigDAO;
    @Autowired
    private WorkFlowGroupOperatorDAO workFlowGroupOperatorDAO;

    /**
     * 处理流程
     * @param handle
     */
    public synchronized WorkFlowOperateResultDTO handle(WorkFlowNextDTO handle){
        //并发处理流程待办
        handleWorkFlowOperate(handle);
        //流程扭转
        WorkFlowOperateResultDTO result = handleWorkFlow(handle);
        return result;
    }

    /**
     * 并发流程待办扭转
     * @param handle
     */
    public void handleWorkFlowOperate(WorkFlowNextDTO handle){

        Date now = new Date();

        Integer flowId = handle.getFlowId();
        WorkFlowNodeDTO currentNode = handle.getCurrentNode();
        WorkFlowNodeDTO.WorkFlowNodeOperateDTO currentNodeOperate = handle.getCurrentNodeOperate();
        WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO currentNodeGroupUser = handle.getCurrentNodeGroupUser();
        List<WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO> nextNodeGroupUserList = handle.getNextNodeGroupUserList();


        WorkFlowOperate currentWorkFlowOperate = null ;

        //流程操作待办查询
        WorkFlowOperateListQuery workFlowOperateListQuery = new WorkFlowOperateListQuery();
        workFlowOperateListQuery.setWorkFlowId(flowId);
        workFlowOperateListQuery.setCurrentNode(currentNode.getCode());
        workFlowOperateListQuery.setOperatorId(currentNodeGroupUser.getOperatorId());
        workFlowOperateListQuery.setState(CommonStateConstant.TRUE.getValue());
        currentWorkFlowOperate = workFlowOperateDAO.selectOne(workFlowOperateListQuery);
        if(null == currentWorkFlowOperate){
            throw new ApiException("流程待办失效");
        }
        //待办扭转
        WorkFlowOperate saveWorkFlowOperate = new WorkFlowOperate();
        saveWorkFlowOperate.setId(currentWorkFlowOperate.getId());
        saveWorkFlowOperate.setState(CommonStateConstant.FALSE.getValue());
        saveWorkFlowOperate.setBody(handle.getBody());
        saveWorkFlowOperate.setContent(handle.getContent());
        saveWorkFlowOperate.setOperateType(currentNodeOperate.getOperateType());
        saveWorkFlowOperate.setGroupOperators(JSONUtils.toJson(nextNodeGroupUserList));
        saveWorkFlowOperate.setUpdateTime(now);
        WorkFlowOperateListQuery saveWorkFlowOperateListQuery = new WorkFlowOperateListQuery();
        saveWorkFlowOperateListQuery.setId(currentWorkFlowOperate.getId());
        saveWorkFlowOperateListQuery.setState(currentWorkFlowOperate.getState());
        int m = workFlowOperateDAO.updateLimit(saveWorkFlowOperate,saveWorkFlowOperateListQuery);
        if(1!=m){
            throw new ApiException("流程待办处理异常");
        }
        boolean exclude = false;
        if(WorkFlowNodeEnum.MEETING.getType().equals(currentNode.getType())){
            if(WorkFlowNodeOperateEnum.REJECT.getCode().equals(currentNodeOperate.getOperateType())){
                exclude = true;
            }
        }else if(WorkFlowNodeEnum.COMPETE.getType().equals(currentNode.getType())){
            exclude = true;
        }
        //是否失效同节点的其他待办
        if(exclude){
            //会签节点拒绝，则使剩余会签节点失效
            WorkFlowOperate saveWorkFlowOperate2 = new WorkFlowOperate();
            saveWorkFlowOperate2.setState(CommonStateConstant.OUT.getValue());
            saveWorkFlowOperate2.setUpdateTime(now);
            WorkFlowOperateListQuery saveWorkFlowOperateListQuery2 = new WorkFlowOperateListQuery();
            saveWorkFlowOperateListQuery2.setWorkFlowId(currentWorkFlowOperate.getWorkFlowId());
            saveWorkFlowOperateListQuery2.setCurrentNode(currentWorkFlowOperate.getCurrentNode());
            saveWorkFlowOperateListQuery2.setState(CommonStateConstant.TRUE.getValue());
            workFlowOperateDAO.updateLimit(saveWorkFlowOperate2,saveWorkFlowOperateListQuery2);
        }
    }

    /**
     * 流程扭转
     * @param handle
     */
    public WorkFlowOperateResultDTO handleWorkFlow(WorkFlowNextDTO handle){
        Date now = new Date();

        Integer flowId = handle.getFlowId();
        String flowType = handle.getFlowType();
        WorkFlowNodeDTO currentNode = handle.getCurrentNode();
        WorkFlowNodeDTO.WorkFlowNodeOperateDTO currentNodeOperate = handle.getCurrentNodeOperate();
        WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO currentNodeGroupUser = handle.getCurrentNodeGroupUser();
        List<WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO> nextNodeGroupUserList = handle.getNextNodeGroupUserList();

        List<WorkFlowConfig> currentNodeWorkFlowConfigList = null;
        WorkFlowConfig currentNodeOperateConfig = null;
        WorkFlowNodeDTO nextNode = null;

        //流程配置查询校验
        WorkFlowConfigListQuery workFlowConfigListQuery = new WorkFlowConfigListQuery();
        workFlowConfigListQuery.setFlowType(flowType);
        workFlowConfigListQuery.setCurrentNode(currentNode.getCode());
        currentNodeWorkFlowConfigList =  workFlowConfigDAO.selectList(workFlowConfigListQuery);
        if(currentNodeWorkFlowConfigList.size()==0){
            throw new ApiException("workflow config missing");
        }
        List<WorkFlowConfig> tempConfigList = currentNodeWorkFlowConfigList.stream()
                .filter(s->s.getOperateType().equals(currentNodeOperate.getOperateType()))
                .collect(Collectors.toList());
        if(tempConfigList.size()==0){
            throw new ApiException("流程配置失效");
        }
        if(tempConfigList.size()>1){
            throw new ApiException("流程配置错误");
        }
        currentNodeOperateConfig = tempConfigList.get(0);

        boolean turnFlag = false;//是否扭转流程状态
        nextNode = new WorkFlowNodeDTO(currentNodeOperateConfig.getNextNode(),currentNodeOperateConfig.getNextNodeType(),currentNodeOperateConfig.getNextNodeName());
        if(WorkFlowNodeEnum.MEETING.getType().equals(currentNode.getType())){
            //会签节点：通过判断当前未完成的待办数来判断会签节点
            WorkFlowOperateListQuery workFlowOperateListQuery = new WorkFlowOperateListQuery();
            workFlowOperateListQuery.setWorkFlowId(flowId);
            workFlowOperateListQuery.setCurrentNode(currentNode.getCode());
            List<WorkFlowOperate> currentWorkFlowOperateList = workFlowOperateDAO.selectList(workFlowOperateListQuery);
            //待办
            List<WorkFlowOperate> listA = currentWorkFlowOperateList.stream()
                    .filter(s->(CommonStateConstant.TRUE.getValue().equals(s.getState()) && !s.getOperatorId().equals(currentNodeGroupUser.getOperatorId()))).collect(Collectors.toList());
            //判断是否会签完成
            turnFlag=(listA.size()==0)?true:false;

        }else if(WorkFlowNodeEnum.COMPETE.getType().equals(currentNode.getType())){
            //抢占节点
            turnFlag = true;
        } else{
            //普通节点
            turnFlag = true;
        }

        if(turnFlag){
            //流程扭转
            WorkFlow saveWorkFlow = new WorkFlow();
            saveWorkFlow.setId(flowId);
            saveWorkFlow.setCurrentNode(nextNode.getCode());
            saveWorkFlow.setCurrentNodeType(nextNode.getType());
            saveWorkFlow.setCurrentNodeName(nextNode.getName());
            saveWorkFlow.setUpdateTime(now);
            saveWorkFlow.setState(CommonStateConstant.TRUE.getValue());
            if(nextNode.getCode().equals(WorkFlowNodeEnum.END.getCode()) ){
                //下个节点为流程结束的节点
                saveWorkFlow.setState(CommonStateConstant.FALSE.getValue());
            }
            int n = workFlowDAO.updateOne(saveWorkFlow);
            if(1!=n){
                throw new ApiException("流程扭转异常");
            }
            //添加待办
            List<WorkFlowOperate> saveWorkFlowOperateList = new ArrayList<>(nextNodeGroupUserList.size());
            WorkFlowOperate saveWorkFlowOperate2 = null;
            if(nextNode.getCode().equals(WorkFlowNodeEnum.END.getCode())){
                saveWorkFlowOperate2 = new WorkFlowOperate();
                saveWorkFlowOperate2.setWorkFlowId(flowId);
                saveWorkFlowOperate2.setCurrentNode(nextNode.getCode());
                saveWorkFlowOperate2.setCurrentNodeName(nextNode.getName());
                saveWorkFlowOperate2.setState(CommonStateConstant.FALSE.getValue());
                saveWorkFlowOperate2.setCreateTime(now);
                saveWorkFlowOperateList.add(saveWorkFlowOperate2);
            }else if( nextNodeGroupUserList!=null &&    nextNodeGroupUserList.size()>0){
                for(WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO u:nextNodeGroupUserList){
                    saveWorkFlowOperate2 = new WorkFlowOperate();
                    saveWorkFlowOperate2.setWorkFlowId(flowId);
                    saveWorkFlowOperate2.setCurrentNode(nextNode.getCode());
                    saveWorkFlowOperate2.setCurrentNodeName(nextNode.getName());
                    saveWorkFlowOperate2.setOperatorId(u.getOperatorId());
                    saveWorkFlowOperate2.setOperatorName(u.getOperatorName());
                    saveWorkFlowOperate2.setState(CommonStateConstant.TRUE.getValue());
                    saveWorkFlowOperate2.setCreateTime(now);
                    saveWorkFlowOperateList.add(saveWorkFlowOperate2);
                }
            }
            if(saveWorkFlowOperateList.size()>0){
                workFlowOperateDAO.insertList(saveWorkFlowOperateList);
            }
        }
        WorkFlowOperateResultDTO result = new WorkFlowOperateResultDTO();
        result.setFlowId(flowId);
        result.setNextWorkFlowNodeDTO(new WorkFlowNodeDTO(nextNode.getCode(),nextNode.getType(),nextNode.getName()));
        return result;
    }

    /*=================================*/
    /*============ WorkFlow =============*/
    /*=================================*/
    @Override
    public ResultMsg<WorkFlowOperateResultDTO> startWorkFlow(WorkFlowStartDTO startDTO) {

        /*
         * 1、流程校验：配置校验
         * 2、系统发起流程
         * 3、流程扭转:用户发起流程
         * 4、拼装下一个节点那信息返回
         */

        Date now = new Date();
        String flowType = startDTO.getFlowType();
        String flowTitle = startDTO.getFlowTitle();
        //当前节点-发起节点
        WorkFlowNodeDTO currentNode = WorkFlowNodeDTO.buildNode(WorkFlowNodeEnum.START);
        WorkFlowNodeDTO.WorkFlowNodeOperateDTO currentNodeOperate = WorkFlowNodeDTO.newNodeOperate(WorkFlowNodeOperateEnum.START.getCode());
        WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO operatorDTO = WorkFlowNodeDTO.newNodeOperateGroupUser(startDTO.getOperatorId(),startDTO.getOperatorName());
        //下一个节点审批人
        List<WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO> nextNodeGroupUserList = startDTO.getNextNodeGroupUserList();
        List<WorkFlowConfig> workFlowConfigList = null;

        //配置校验（必须以 start 节点开始）
        WorkFlowConfigListQuery workFlowConfigListQuery = new WorkFlowConfigListQuery();
        workFlowConfigListQuery.setFlowType(flowType);
        workFlowConfigListQuery.setCurrentNode(currentNode.getCode());
        workFlowConfigList =  workFlowConfigDAO.selectList(workFlowConfigListQuery);
        if(workFlowConfigList.size()==0){
            throw new ApiException("workflow config missing");
        }

        //系统发起流程（默认节点为发起节点，操作人为发起人）
        WorkFlow workFlow = new WorkFlow();
        workFlow.setTitle(flowTitle);
        workFlow.setType(flowType);
        workFlow.setName(workFlowConfigList.get(0).getFlowName());
        workFlow.setBody(startDTO.getBody());
        workFlow.setCurrentNode(currentNode.getCode());
        workFlow.setCurrentNodeType(currentNode.getType());
        workFlow.setCurrentNodeName(currentNode.getName());
        workFlow.setOperatorId(operatorDTO.getOperatorId());
        workFlow.setOperatorName(operatorDTO.getOperatorName());
        workFlow.setCreateTime(now);
        workFlow.setUpdateTime(now);
        Integer workFlowId = workFlowDAO.insertOne(workFlow);
        workFlow.setId(workFlowId);

        //添加流程发起的待办（流程节点为发起节点，处理人为流程发起人）
        WorkFlowOperate saveWorkFlowOperate =  new WorkFlowOperate();
        saveWorkFlowOperate.setWorkFlowId(workFlowId);
        saveWorkFlowOperate.setCurrentNode(currentNode.getCode());
        saveWorkFlowOperate.setCurrentNodeName(currentNode.getName());
        saveWorkFlowOperate.setOperatorId(operatorDTO.getOperatorId());
        saveWorkFlowOperate.setOperatorName(operatorDTO.getOperatorName());
        saveWorkFlowOperate.setState(CommonStateConstant.TRUE.getValue());
        saveWorkFlowOperate.setCreateTime(now);
        workFlow.setBody(startDTO.getBody());
        Integer workFlowOperateId = workFlowOperateDAO.insertOne(saveWorkFlowOperate);
        saveWorkFlowOperate.setId(workFlowOperateId);

        //流程扭转（组装节点扭转，）
        WorkFlowNextDTO nextDTO = new WorkFlowNextDTO();
        nextDTO.setCurrentNode(currentNode);
        nextDTO.setCurrentNodeOperate(currentNodeOperate);
        nextDTO.setFlowId(workFlowId);
        nextDTO.setFlowType(flowType);
        nextDTO.setCurrentNodeGroupUser(operatorDTO);
        nextDTO.setNextNodeGroupUserList(nextNodeGroupUserList);
        nextDTO.setBody(startDTO.getBody());

        WorkFlowOperateResultDTO result = handle(nextDTO);
        return new ResultMsg<>(ResultConstant.SUCCESS,"流程发起成功",result);
    }

    @Override
    public ResultMsg<WorkFlowStopDTO> stopWorkFlow(WorkFlowStopDTO stopDTO) {
        return null;
    }

    @Override
    public ResultMsg<WorkFlowOperateResultDTO> nextWorkFlow(WorkFlowNextDTO nextDTO) {
        Integer flowId = nextDTO.getFlowId();
        String flowType = nextDTO.getFlowType();
        WorkFlowNodeDTO currentNode = nextDTO.getCurrentNode();
        WorkFlowNodeDTO.WorkFlowNodeOperateDTO currentNodeOperate = nextDTO.getCurrentNodeOperate();
        WorkFlowNodeDTO.WorkFlowNodeGroupOperatorDTO currentNodeGroupUser = nextDTO.getCurrentNodeGroupUser();

        WorkFlow workFlow = null;
        List<WorkFlowConfig> currentNodeWorkFlowConfigList = null;
        WorkFlowOperate currentWorkFlowOperate = null ;

        //流程记录查询校验
        WorkFlowListQuery workFlowListQuery = new WorkFlowListQuery();
        workFlowListQuery.setId(flowId);
        workFlowListQuery.setCurrentNode(currentNode.getCode());
        workFlow = workFlowDAO.selectOne(workFlowListQuery);
        if(null == workFlow){
            return new ResultMsg<>(ResultConstant.FAILED,"流程已失效");
        }

        //流程操作待办查询
        WorkFlowOperateListQuery workFlowOperateListQuery = new WorkFlowOperateListQuery();
        workFlowOperateListQuery.setWorkFlowId(flowId);
        workFlowOperateListQuery.setCurrentNode(currentNode.getCode());
        workFlowOperateListQuery.setOperatorId(currentNodeGroupUser.getOperatorId());
        workFlowOperateListQuery.setState(CommonStateConstant.TRUE.getValue());
        currentWorkFlowOperate = workFlowOperateDAO.selectOne(workFlowOperateListQuery);
        if(null == currentWorkFlowOperate){
            return new ResultMsg<>(ResultConstant.FAILED,"流程待办失效");
        }

        //流程配置查询校验
        WorkFlowConfigListQuery workFlowConfigListQuery = new WorkFlowConfigListQuery();
        workFlowConfigListQuery.setFlowType(flowType);
        workFlowConfigListQuery.setCurrentNode(currentNode.getCode());
        currentNodeWorkFlowConfigList =  workFlowConfigDAO.selectList(workFlowConfigListQuery);
        if(currentNodeWorkFlowConfigList.size()==0){
            return new ResultMsg<>(ResultConstant.FAILED,"流程配置已失效");
        }
        List<WorkFlowConfig> tempConfigList = currentNodeWorkFlowConfigList.stream()
                .filter(s->s.getOperateType().equals(currentNodeOperate.getOperateType()))
                .collect(Collectors.toList());
        if(tempConfigList.size()==0){
            return new ResultMsg<>(ResultConstant.FAILED,"流程配置已失效");
        }
        if(tempConfigList.size()>1){
            return new ResultMsg<>(ResultConstant.FAILED,"流程配置冲突");
        }

        //流程扭转
        WorkFlowOperateResultDTO result = handle(nextDTO);
        return new ResultMsg<>(ResultConstant.SUCCESS,"流程扭转成功",result);
    }

    @Override
    public ResultMsg<WorkFlowCurrentDTO> currentWorkFlowNode(Integer flowId) {

        WorkFlow workFlow = workFlowDAO.selectById(flowId);
        //流程状态校验
        if(workFlow==null){
            return new ResultMsg<>(ResultConstant.FAILED,"流程已失效");
        }
        String flowType = workFlow.getType();
        WorkFlowConfigListQuery workFlowConfigListQuery = new WorkFlowConfigListQuery();
        workFlowConfigListQuery.setFlowType(flowType);
        workFlowConfigListQuery.setCurrentNode(workFlow.getCurrentNode());
        List<WorkFlowConfig> workFlowConfigList =  workFlowConfigDAO.selectList(workFlowConfigListQuery);

        //组装当前流程信息明细
        WorkFlowCurrentDTO workFlowCurrentDTO = new WorkFlowCurrentDTO();
        workFlowCurrentDTO.setFlowId(flowId);
        workFlowCurrentDTO.setFlowType(flowType);
        workFlowCurrentDTO.setBody(workFlow.getBody());
        List<WorkFlowNodeDTO.WorkFlowNodeOperateDTO> operateDTOList = Lists.newArrayList();
        WorkFlowNodeDTO currentNode = new WorkFlowNodeDTO(workFlow.getCurrentNode(),workFlow.getCurrentNodeType(),workFlow.getCurrentNodeName());
        workFlowConfigList.forEach(s->{
            operateDTOList.add(WorkFlowNodeDTO.newNodeOperate(s.getOperateType()));
        });
        currentNode.setOperates(operateDTOList);
        workFlowCurrentDTO.setCurrentNode(currentNode);
        workFlowCurrentDTO.setFirstNodeGroupOperator(WorkFlowNodeDTO.newNodeOperateGroupUser(workFlow.getOperatorId(),workFlow.getOperatorName()));
        return new ResultMsg<>(ResultConstant.SUCCESS,null,workFlowCurrentDTO);
    }

    /*=================================*/
    /*============ WorkFlow =============*/
    /*=================================*/
    @Override
    public ResultPage<WorkFlowListDTO> listWorkFlow(WorkFlowListQuery query) {
        List<WorkFlowListDTO> data = new ArrayList<>();
        List<WorkFlow> list = workFlowDAO.selectList(query);
            Optional.ofNullable(list).orElse(Lists.newArrayList())
            .stream().forEach(item->{
                WorkFlowListDTO d = new WorkFlowListDTO();
                d.setM(MapperFacadeUtils.map(item,WorkFlowListDTO.WorkFlow.class));
                data.add(d);
            });
        return new ResultPage(ResultConstant.SUCCESS,data,data.size());
    }

    @Override
    public ResultMsg<WorkFlowListDTO> findWorkFlow(Integer id) {
        WorkFlowListDTO d = new WorkFlowListDTO();
        WorkFlow workFlow = workFlowDAO.selectById(id);
        d.setM(MapperFacadeUtils.map(workFlow,WorkFlowListDTO.WorkFlow.class));
        return new ResultMsg<>(ResultConstant.SUCCESS,null,d);
    }

    @Override
    public ResultMsg<WorkFlowSaveDTO> addWorkFlow(WorkFlowSaveDTO saveDTO) {
        Integer id = workFlowDAO.insertOne(MapperFacadeUtils.map(saveDTO.getM(),WorkFlow.class));
        saveDTO.getM().setId(id);
        return new ResultMsg<>(ResultConstant.SUCCESS,null,saveDTO);
    }

    @Override
    public ResultMsg<WorkFlowSaveDTO> editWorkFlow(WorkFlowSaveDTO saveDTO) {
        workFlowDAO.updateOne(MapperFacadeUtils.map(saveDTO.getM(),WorkFlow.class));
        return new ResultMsg<>(ResultConstant.SUCCESS,null,saveDTO);
    }

    @Override
    public ResultMsg deleteWorkFlow(Integer id) {
        workFlowDAO.deleteOne(id);
        return new ResultMsg(ResultConstant.SUCCESS);
    }
    /*=================================*/
    /*============ WorkFlowOperate =============*/
    /*=================================*/

    @Override
    public ResultPage<WorkFlowOperateListDTO> listWorkFlowOperate(WorkFlowOperateListQuery query) {
        List<WorkFlowOperateListDTO> data = new ArrayList<>();
        List<WorkFlowOperate> list = workFlowOperateDAO.selectList(query);
        Set<Integer> workFlowIdSet = new HashSet<>();
        Optional.ofNullable(list).orElse(Lists.newArrayList())
                .stream().forEach(item->{
            WorkFlowOperateListDTO d = new WorkFlowOperateListDTO();
            d.setM(MapperFacadeUtils.map(item,WorkFlowOperateListDTO.WorkFlowOperate.class));
            d.setFlowId(item.getWorkFlowId());
            workFlowIdSet.add(item.getWorkFlowId());
            data.add(d);
        });
        //填充流程信息
        if(workFlowIdSet.size()>0){
            WorkFlowListQuery workFlowListQuery = new WorkFlowListQuery();
            workFlowListQuery.setIdList(new ArrayList(workFlowIdSet));
            List<WorkFlow> workFlowList = workFlowDAO.selectList(workFlowListQuery);
            if(workFlowList!=null&&workFlowList.size()>0){
                Map<Integer,String> workFlowIdMapTitle =  workFlowList.stream().collect(Collectors.toMap(s->s.getId(),s->s.getTitle()));
                data.forEach(s->{
                    s.setFlowTitle(workFlowIdMapTitle.get(s.getFlowId()));
                });
            }
        }
        return new ResultPage(ResultConstant.SUCCESS,data,data.size());
    }
}